package com.gblw.rjkf.pj.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import com.gblw.rjkf.pj.entity.SysDictDetails;
import com.gblw.rjkf.pj.service.SysDictDetailsService;
import com.gblw.rjkf.pj.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * SysDictDetailsController(SysDictDetails)
 *
 * @author wj
 * @since 2024-09-16 17:36:43
 */
@Api(tags = {"SysDictDetails"})
@RestController
@RequestMapping("sys/sysDictDetails")
public class SysDictDetailsController {

    /**
     * 服务对象
     */
    @Resource
    private SysDictDetailsService sysDictDetailsService;

    /**
     * 分页查询所有数据
     * @return 所有数据
     */
    @SaCheckPermission(value = "sys:dict:list")
    @ApiOperation("分页查询所有数据")
    @GetMapping("/list")
    public Result selectAll(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                            @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize,
                            @RequestParam(value = "name") String name,
                            @RequestParam(value = "dictId") String dictId) {
        return sysDictDetailsService.page(pageNum, pageSize, dictId, name);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @SaCheckPermission(value = "sys:dict:list")
    @ApiOperation("通过主键查询单条数据")
    @GetMapping("getById/{id}")
    public Result selectOne(@PathVariable Serializable id) {
        return Result.success("查询成功",sysDictDetailsService.getById( id));
    }

    /**
     * 新增数据
     *
     * @param sysDictDetails 实体对象
     * @return 新增结果
     */
    @SaCheckPermission(value = "sys:dict:insert")
    @ApiOperation("新增数据")
    @PostMapping("/insert")
    public Result insert(@RequestBody SysDictDetails sysDictDetails) {
        return sysDictDetailsService.insert(sysDictDetails);
    }

    /**
     * 修改数据
     *
     * @param sysDictDetails 实体对象
     * @return 修改结果
     */
    @SaCheckPermission(value = "sys:dict:update")
    @ApiOperation("修改数据")
    @PostMapping("/update")
    public Result update(@RequestBody SysDictDetails sysDictDetails) {
        return sysDictDetailsService.update(sysDictDetails);
    }

    /**
     * 批量删除数据
     *
     * @param idList 主键集合
     * @return 删除结果
     */
    @SaCheckPermission(value = "sys:dict:delete")
    @ApiOperation("批量删除数据")
    @PostMapping("/delete")
    public Result delete(@RequestParam("idList") List<Serializable> idList) {
        int result = 0;
        if (idList != null && idList.size() > 0) {
            sysDictDetailsService.removeByIds(idList);
        }
        ;
        return Result.success("删除成功", "");
    }

    /**
     * 批量删除数据
     *
     * @param id 主键
     * @return 删除结果
     */
    @SaCheckPermission(value = "sys:dict:delete")
    @ApiOperation("单个删除数据")
    @PostMapping("/deleteIds/{id}")
    public Result delete(@PathVariable Serializable id) {
        sysDictDetailsService.removeById(id);
        return Result.success("删除成功", "");
    }
}
